<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>动态列表</title>
    <link rel="stylesheet" type="text/css" th:href="@{/js/layui/css/layui.css}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/fyn/style.css/}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/fyn/my.css/}" media="all">

</head>
<body class="body">


<div class="my-btn-box layui-form">
    <span class="fr">
        <div class="layui-input-inline">
            <input type="text" autocomplete="off" name="userId" placeholder="用户ID" class="layui-input height33">
        </div>
        <div class="layui-input-inline">
           <select lay-filter="dis">
               <option value="">广场状态</option>
               <option value="1">显示</option>
               <option value="0">不显示</option>
           </select>
        </div>

        <button class="layui-btn layui-btn-sm" id="search"><i class="layui-icon">&#xe615;</i></button>
    </span>
</div>

<!-- 表格 -->
<div id="dateTable" lay-filter="event"></div>
<div class="height50"></div>
<script th:src="@{/js/layui/layui.js}"></script>
<script th:src="@{/js/fyn/index.js}"></script>
<script th:src="@{/js/fyn/my.js}"></script>
<script type="text/javascript" th:src="@{/js/vip/vip_comm.js}"></script>
<script type="text/javascript" th:src="@{/js/vip/vip_table.js}"></script>
<script type="text/javascript" th:inline="javascript">

    // layui方法
    layui.use(['table', 'form', 'laypage', 'layer', 'vip_table'], function () {

        // 操作对象
        var form = layui.form
            , table = layui.table
            , layer = layui.layer
            , vipTable = layui.vip_table
            , $ = layui.jquery;

        // 表格渲染
        var tableIns = table.render({
            elem: '#dateTable'                  //指定原始表格元素选择器（推荐id选择器）
            , height: "full"    //容器高度
            // , skin: 'line'
            , even: 'true'
            , cols: [[                  //标题栏
                {
                    field: 'menu.id', title: '用户ID', minWidth: '100', align: 'center', templet: function (d) {
                    return d.userId;
                }

                }
                , {
                    field: 'menu.name', title: '内容', align: 'center', minWidth: '250', templet: function (d) {
                        return d.content;
                    }
                }
                , {
                    field: 'menu.name', title: '图片', align: 'center', minWidth: '100', templet: function (d) {
                        var arr = d.imgs == null ? '' : d.imgs.split(",");
                        var h = '';
                        for (var i = 0; i < arr.length; i++) {
                            h += "<a style='margin-left: 5px;' target='_blank' href='" + arr[i] + "'><img src='" + arr[i] + "' width='60' height='80'  /></a>"
                        }
                        return h;
                    }
                }

                , {
                    field: 'menu.name', title: '视频', align: 'center', minWidth: '100', templet: function (d) {
                        var arr = d.videos == null ? '' : d.videos.split(",");
                        var h = '';
                        for (var i = 0; i < arr.length; i++) {
                            h += "<a style='margin-left: 5px;' target='_blank' href='" + arr[i] + "?x-oss-process=video/snapshot,t_10000,m_fast'><img src='" + arr[i] + "?x-oss-process=video/snapshot,t_10000,m_fast' width='60' height='80'  /></a>"
                        }
                        return h;
                    }
                }

                , {
                    field: 'menu.name', title: '标签', align: 'center', minWidth: '100', templet: function (d) {
                        return d.sign==null?'':d.sign;
                    }
                }
                , {
                    field: 'orderWeight', title: '排序权重', align: 'center', minWidth: '100'
                }

                , {
                    field: 'menu.name', title: '广场状态', align: 'center', minWidth: '100', templet: function (d) {
                        return (d.publicStatus == null || d.publicStatus == 0) ? '否' : '是';
                    }
                }
                , {
                    field: 'user.ctime',
                    align: 'center',
                    title: '创建时间',
                    minWidth: '170',
                    templet: function (d) {
                        return new Date(d.ctime).Format("yyyy-MM-dd hh:mm:ss");
                    }
                }
                , {
                    title: '操作', align: 'center',width: "250", templet: function (d) {
                        var html = '';
                        if (d.publicStatus == 0 ||d.publicStatus == null) {
                            html += '<a class="layui-btn layui-bg-orange layui-btn-xs" lay-event="deposit"><i class="layui-icon layui-icon-set"></i>设置</a>';
                        } else {
                            html += '<a class="layui-btn layui-bg-orange layui-btn-xs" lay-event="cancle"><i class="layui-icon layui-icon-close"></i>取消</a>';
                        }
                        html += '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="orderWeight"><i class="layui-icon layui-icon-top"></i>置顶</a>';
                        html += '<a class="layui-btn layui-bg-red layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>';
                        return html;
                    }
                } //这里的toolbar值是模板元素的选择器
            ]]
            , id: 'dataCheck'
            , url: [[${basePath}]] + '/trend/list'
            , method: 'get'
            , page: true
            , limits: [10, 30, 60, 90, 150, 300]
            , toolbar: '#topOperate'
            , limit: 10 //默认采用0
            , loading: true
            // , where: getJson()
            , done: function (res, curr, count) {
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                $("td[data-field='content']").each(function () {
                    $(this).find(".layui-table-cell").removeClass('layui-table-cell');
                });


            }
        });


        //头工具栏事件
        table.on('toolbar(event)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;

            switch (obj.event) {
                case 'toSave':
                    layer.open({
                        type: 2,
                        title: '菜单增加',
                        shadeClose: true,
                        shade: 0.2,
                        maxmin: true, //开启最大化最小化按钮
                        area: ['650px', '550px'],
                        content: [[${basePath}]] + '/menu/save/index'
                    });
                    break;
            }
        });

        table.on('tool(event)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                layer.open({
                    type: 2,
                    title: '用户详情',
                    shadeClose: true,
                    shade: 0.2,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['650px', '550px'],
                    content: [[${basePath}]] + '/member/detail?id=' + data.id
                });

            }
            //设置广场可见
            else if (obj.event === 'deposit') {
                layer.confirm("确定设置成功广场可见状态?", {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    $.ajax({
                        type: "post",
                        url: [[${basePath}]] + "/trend/public/set",
                        data: {id: data.id},
                        success: function (res) {
                            if (res.success) {
                                layer.msg("设置成功！", {icon: 1}, 1000);

                                setTimeout(function () {
                                    tableIns.reload();
                                }, 1000);
                            } else {
                                layer.msg(res.msg, {icon: 2}, 2000);
                            }
                        }
                    });

                });
            }
            // 取消广场可见
            else if (obj.event === 'cancle') {
                layer.confirm("确定取消成功广场可见状态?", {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    $.ajax({
                        type: "post",
                        url: [[${basePath}]] + "/trend/public/cancle",
                        data: {id: data.id},
                        success: function (res) {
                            if (res.success) {
                                layer.msg("取消成功！", {icon: 1}, 1000);

                                setTimeout(function () {
                                    tableIns.reload();
                                }, 1000);
                            } else {
                                layer.msg(res.msg, {icon: 2}, 2000);
                            }
                        }
                    });


                });
            }
            // 删除记录
            else if (obj.event === 'del') {
                layer.confirm("确定删除该记录?", {
                    icon: 5,
                    title: '提示'
                }, function (index) {
                    $.ajax({
                        type: "post",
                        url: [[${basePath}]] + "/trend/public/delete",
                        data: {id: data.id},
                        success: function (res) {
                            if (res.success) {
                                layer.msg("删除成功！", {icon: 1}, 1000);
                                setTimeout(function () {
                                    tableIns.reload();
                                }, 1000);
                            } else {
                                layer.msg(res.msg, {icon: 2}, 2000);
                            }
                        }
                    });


                });
            }
            // 设置排序权重
            else if (obj.event === 'orderWeight') {
                layer.prompt({
                    formType: 0,
                    value: data.orderWeight,
                    title: '请输入排序权重，值越小越靠前',
                    area: ['800px', '350px'] //自定义文本域宽高
                }, function (value, index, elem) {
                    if (value == null || value == '') {
                        layer.msg("排序权重不能为空", {icon: 6, time: 1500});
                        return;
                    }
                    $.ajax({
                        type: "post",
                        url: [[${basePath}]] + "/trend/public/orderWeight",
                        data: {id: data.id, orderWeight: value},
                        success: function (res) {
                            layer.close(index);
                            if (res.success) {
                                layer.msg(res.msg, {icon: 1}, 2000);
                                setTimeout(function () {
                                    tableIns.reload()
                                }, 2000);
                            } else {
                                layer.msg(res.msg, {icon: 2}, 2000);
                            }
                        }
                    });
                });


            }


        });


        var status = 0;
        form.on('switch(status)', function (data) {
            if (!data.elem.checked) {
                status = 1;
            } else {
                status = 0;
            }

            $("#search").click();

        });

        var groupAuth = null;
        form.on('select(dis)', function (data) {
            groupAuth = (data.value); //得到被选中的值
        });


        function getJson() {
            return {
                where: {
                    publicStatus: groupAuth
                    , mobile: $("input[name='mobile']").val()
                    , ucode: $("input[name='ucode']").val()
                    , userId: $("input[name='userId']").val()
                }
            };
        }

        $("#search").click(function () {
            tableIns.reload({
                where: {
                    publicStatus: groupAuth
                    , mobile: $("input[name='mobile']").val()
                    , ucode: $("input[name='ucode']").val()
                    , userId: $("input[name='userId']").val()
                },
                page: {
                    curr: 1
                }
            });
        })


    });
</script>
<!-- 表格操作按钮集 -->
<script type="text/html" id="barOption">
    <i class="layui-icon layui-icon-delete" title="删除" style="cursor: pointer" lay-event="deposit"></i>
</script>
</body>
</html>